package com.sskj.mine.http;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.App;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.bean.AppVersionBean;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.util.APKVersionCodeUtils;
import com.sskj.mine.bean.AssetListBean;
import com.sskj.mine.bean.GoogleCode;
import com.sskj.mine.bean.InviteStatusBean;
import com.sskj.mine.bean.MineShopBean;
import com.sskj.mine.bean.QuestionBean;
import com.sskj.mine.bean.TwoCodeBean;

import java.util.List;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {
    /**
     * 资产列表
     * @return
     */
    public GetRequest<HttpData<List<AssetListBean>>> getAssetList() {
        return OkGo.<HttpData<List<AssetListBean>>>get(HttpConfig.BASE_URL + HttpConfig.ASEET_LIST)
                ;
    }

    public PostRequest<HttpData> feedBack(String content, String contact) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FEEDBACK)
                .params("id", SPUtil.get(SPConfig.ID, ""))
                .params("content", content)
                .params("contactInformation", contact);
    }

    public GetRequest<HttpData<PageBean<QuestionBean>>> getQuestionList(int page) {
        return OkGo.<HttpData<PageBean<QuestionBean>>>get(HttpConfig.BASE_URL + HttpConfig.QUESTION_LIST)
                .params("pageNumber", page)
                .params("pageSize", 10);
    }

    public PostRequest<HttpData> bindGoogle(String chromeCode, String authCode, String secret, String qrcode) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BINDCHROME)
                .params("code", chromeCode)
                .params("stockUserId", SPUtil.get(SPConfig.ID, ""))
                .params("telCode", authCode)
                .params("secret", secret)
                .params("qrcode", qrcode)
                .params("areaCode", SPUtil.get(SPConfig.AREA_CODE, "").replace("+", ""));

    }

    public PostRequest<HttpData<GoogleCode>> googleQr() {
        return OkGo.<HttpData<GoogleCode>>post(HttpConfig.BASE_URL + HttpConfig.GOOGLE_QR);
    }

    public PostRequest<HttpData> bindMobile(String mobile, String code, String tpwd, String areaCode) {

        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BIND_MOBILE_OR_EMAIL)
                .params("account", mobile) // 手机号
                .params("code", code)  // 验证码
                .params("dealPswd", tpwd, true)
                .params("areaCode", areaCode.replace("+", ""));
    }

    public PostRequest<HttpData> updateMobile(String mobile, String id, String tpwd) {

        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.UPDATE_MOBILE_OR_EMAIL)
                .params("account", mobile) // 手机号
                .params("id", id) // 手机号
                .params("tradePswd", tpwd, true);
    }

    public GetRequest<HttpData<String>> getContract() {
        return OkGo.<HttpData<String>>get(HttpConfig.BASE_URL + HttpConfig.CONTRACT);

    }

    public PostRequest<HttpData<AppVersionBean>> checkVersion() {
        return OkGo.<HttpData<AppVersionBean>>post(HttpConfig.BASE_URL + HttpConfig.VERSION)
                .params("version", APKVersionCodeUtils.getVerName(App.INSTANCE))
                .params("type", "2");
    }

    public GetRequest<HttpData> cancelShop() {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.SHOPCANCEL)
                .params("id", SPUtil.get(SPConfig.ID, ""));
    }

    public GetRequest<HttpData> openGoogleVerify(String code) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.OPENCHROME)
                .params("code", code)
                .params("stockUserId", SPUtil.get(SPConfig.ID, ""));
    }

    public GetRequest<HttpData> closeGoogleVerify(String code, String telCode) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.CLOSECHROME)
                .params("code", code)
                .params("stockUserId", SPUtil.get(SPConfig.ID, ""))
                .params("telCode", telCode);
    }

    public GetRequest<HttpData> untriedGoogleVerify(String code, String telCode) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.UNBINDCHROME)
                .params("code", code)
                .params("stockUserId", SPUtil.get(SPConfig.ID, ""))
                .params("telCode", telCode)
                .params("areaCode", SPUtil.get(SPConfig.AREA_CODE, "").replace("+", ""));
    }

    public PostRequest<HttpData<MineShopBean>> getShopMoney() {
        return OkGo.<HttpData<MineShopBean>>post(HttpConfig.BASE_URL + HttpConfig.GETMONEY);

    }

    public PostRequest<HttpData<Object>> applyShop() {
        return OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.SHOPVERIFY);
    }

    public PostRequest<HttpData> setLoginPwd(String newPwd, String oldPwd) {

        return OkGo.<HttpData>post(HttpConfig.BASE_URL + (HttpConfig.SET_LOGIN_PWD))
                .params("pswd", newPwd, true)
                .params("oldPswd", oldPwd, true);
    }

    public PostRequest<HttpData> setFundPwd(String code,String pwd) {
        String account = SPUtil.get(SPConfig.USER_ACCOUNT, "");
       return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SETFUNDPWD)
                .params("id", SPUtil.get(SPConfig.ID, ""))
                .params("code", code)
                .params("areaCode",account.contains("@")?null:SPUtil.get(SPConfig.AREA_CODE,"").replace("+",""))
                .params("account", SPUtil.get(SPConfig.USER_ACCOUNT, ""))
                .params("dealPswd", pwd,true);
    }

    public GetRequest<HttpData<TwoCodeBean>> getData() {
        return OkGo.<HttpData<TwoCodeBean>>get(HttpConfig.BASE_URL + (HttpConfig.GET_TWO_CODE))
                ;
    }

    public GetRequest<HttpData<InviteStatusBean>> getInvite() {
        return OkGo.<HttpData<InviteStatusBean>>get(HttpConfig.BASE_URL + (HttpConfig.GET_INVITE))
                ;
    }
}